<template>
  <el-dialog title="分配角色" :visible="showRoleDialog" append-to-body @close="hClose">
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id"> {{ item.name }} </el-checkbox>

    </el-checkbox-group>
    <el-row>
      <el-button type="primary" @click="hSave">确认</el-button>
      <el-button>取消</el-button>
    </el-row>

  </el-dialog>
</template>

<script>
import { getEnableRoleList, assignRoles } from '@/api/rols'
import { getEmployeeDetail } from '@/api/employment'
export default {
  props: {
    showRoleDialog: {
      type: Boolean,
      required: true
    },
    curId: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      roleList: [], // 所有角色的数据
      roleIds: []
    }
  },
  created() {
    this.getRoleEnabledList()
  },
  methods: {
    async hSave() {
      const res = await assignRoles({ id: this.curId, roleIds: this.roleIds })
      console.log(res)
      //  提示用户 修改成功
      this.$message.success('分配修改成功')
      //  关闭弹框
      this.hClose()
    },
    async getRolesById() {
      const res = await getEmployeeDetail(this.curId)
      console.log('获取当前员工的角色信息', res)
      // 回填
      this.roleIds = res.data.roleIds
    },
    async getRoleEnabledList() {
      const res = await getEnableRoleList()
      console.log(res)
      this.roleList = res.data
    },
    hClose() {
      this.$emit('update:showRoleDialog', false)
    }

  }
}
</script>

<style>

</style>
